package com.tomehay.termprojectmanage_server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tomehay.termprojectmanage_server.enums.ResponseCode;
import com.tomehay.termprojectmanage_server.pojo.Model.Termproject;
import com.tomehay.termprojectmanage_server.mapper.TermprojectMapper;
import com.tomehay.termprojectmanage_server.pojo.VO.ResultVO;
import com.tomehay.termprojectmanage_server.pojo.VO.TermProjectVO;
import com.tomehay.termprojectmanage_server.service.TermprojectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author tomehay
 * @since 2023-06-20
 */
@Service
public class TermprojectServiceImpl extends ServiceImpl<TermprojectMapper, Termproject> implements TermprojectService {

    @Resource
    TermprojectMapper termprojectMapper;


    @Override
    public ResultVO<List<Termproject>> GetTermProjectByCourseId(int courseId) {
        QueryWrapper queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("course_id",courseId);
        List<Termproject> list = termprojectMapper.selectList(queryWrapper);
        return new ResultVO<>(ResponseCode.auto(list),list);
    }

    @Override
    public ResultVO<Void> DeleteTermProjectById(int id) {
        termprojectMapper.deleteById(id);
        return new ResultVO<>(ResponseCode.OK);
    }

    @Override
    public ResultVO<Void> CreateTermProject(Termproject termproject) {
        termproject.setCreateTime(LocalDateTime.now());
        termproject.setTermProjectNo(String.valueOf(termproject.getCourseId())+System.currentTimeMillis());
        termprojectMapper.insert(termproject);
        return new ResultVO<>(ResponseCode.OK);
    }

    @Override
    public ResultVO<Void> UpDateTermProject(Termproject termproject) {
        termprojectMapper.updateById(termproject);
        return new ResultVO<>(ResponseCode.OK);
    }

    @Override
    public ResultVO<List<TermProjectVO>> GetTermProjectByCourseIdAndStudentId(int courseId, int studentId) {
        List<TermProjectVO> termprojects = termprojectMapper.GetTermProjects(courseId,studentId);
        return new ResultVO<>(ResponseCode.auto(termprojects),termprojects);
    }


}
